package com.iyao_app.adapter;

import android.content.Context;
import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.facebook.drawee.generic.RoundingParams;
import com.facebook.drawee.view.SimpleDraweeView;
import com.iyao_app.R;
import com.iyao_app.util.ResourcesUtils;
import com.iyaowoqu.base_library.util.ImageUtils;
import com.lzy.imagepicker.bean.ImageItem;

import java.util.List;

/**
 * 作者 :  胡家兵
 * 时间 :  2017/11/22.
 */

public class SignSeletPictureAdapter extends BaseRecyclerAdapter<ImageItem, RecyclerView.ViewHolder> {
    public enum ITEM_TYPE {
        TYPE_FIRST, TYPE_PICTURE, TYPE_MORE
    }


    public SignSeletPictureAdapter(Context context, List<ImageItem> data) {
        super(context, data);
    }

    @Override
    protected RecyclerView.ViewHolder getViewHolder(int viewType) {
        RecyclerView.ViewHolder viewHolder;
        if (viewType == ITEM_TYPE.TYPE_FIRST.ordinal()) {
            viewHolder = new ViewHolder(mInflater.inflate(R.layout.item_take_photo, null));
        } else if (viewType == ITEM_TYPE.TYPE_MORE.ordinal()) {
            viewHolder = new ViewHolder(mInflater.inflate(R.layout.item_more, null));
        } else {
            viewHolder = new ViewHolder(mInflater.inflate(R.layout.item_picture_sign, null));
        }
        return viewHolder;
    }

    @Override
    public int getItemViewType(int position) {
        int type = ITEM_TYPE.TYPE_FIRST.ordinal();
        if (position == 0) {
            type = ITEM_TYPE.TYPE_FIRST.ordinal();
        } else if (position == data.size() - 1) {
            type = ITEM_TYPE.TYPE_MORE.ordinal();
        } else {
            type = ITEM_TYPE.TYPE_PICTURE.ordinal();
        }
        return type;
    }

    @Override
    protected void onBindViewHolder_(RecyclerView.ViewHolder holder, int position) {
        int itemViewType = getItemViewType(position);
        ImageItem imageItem = data.get(position);
        if (itemViewType==ITEM_TYPE.TYPE_PICTURE.ordinal()) {
            RoundingParams roundingParams =   ((ViewHolder) holder).mSdvPhoto.getHierarchy().getRoundingParams();
            if (data.get(position).select) {
                roundingParams.setBorderColor(ResourcesUtils.getColor(R.color.app_orange_ff773d));
                ((ViewHolder) holder).mSdvPhoto.getHierarchy()
                        .setRoundingParams(roundingParams);
            } else {
                roundingParams.setBorderColor(Color.TRANSPARENT);
                ((ViewHolder) holder).mSdvPhoto.getHierarchy()
                        .setRoundingParams(roundingParams);
            }
            ((ViewHolder) holder).mSdvPhoto.setImageURI(ImageUtils.IMAGE_FILE + imageItem.path);
        }else {

        }
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        SimpleDraweeView mSdvPhoto;

        ViewHolder(View view) {
            super(view);
            mSdvPhoto = view.findViewById(R.id.sdv_photo);
        }
    }

    static class ViewHolderFirst extends RecyclerView.ViewHolder {

        ViewHolderFirst(View view) {
            super(view);

        }
    }

    static class ViewHolderMore extends RecyclerView.ViewHolder {

        ViewHolderMore(View view) {
            super(view);

        }
    }
}
